package cn.yutong.framework;

import static cn.yutong.framework.constant.RetConstant.AJAX_ERROR;
import static cn.yutong.framework.constant.RetConstant.AJAX_SUCCESS;
import static cn.yutong.framework.constant.RetConstant.NO_AUTH;
import static cn.yutong.framework.constant.RetConstant.SERVER_ERROR_CODE;
import static cn.yutong.framework.constant.RetConstant.SERVER_TIMEOUT;

import java.io.Serializable;

/**
 * @className: RestResponse
 * @author: lnexin@aliyun.com
 * REST 接口的通用返回模板
 */
public class RestResponse implements Serializable {
    private static final long serialVersionUID = 999227731L;

    private final static String SUCCESS_MSG = "success";
    private final static String FAILURE_MSG = "failure, unknown error ";
    private final static String NO_AUTH_MSG = "sorry, current login No authority for some request";
    private final static String TIMEOUT_MSG = "this request time-out, include network error and server time-out ";
    private final static String SERVER_ERROR_MSG = "server error ";

    private Integer ret;
    private String msg;
    private Object data;

    private RestResponse() {
    }

    private RestResponse(Integer ret, String msg, Object data) {
        this.ret = ret;
        this.msg = msg;
        this.data = data;
    }

    public static RestResponse newEntity() {
        return new RestResponse();
    }

    public static RestResponse newEntity(int ret, String msg, Object object) {
        return new RestResponse(ret, msg, object);
    }


    public static RestResponse success(Object object) {
        return new RestResponse(AJAX_SUCCESS, SUCCESS_MSG, object);
    }

    public static RestResponse success(String msg, Object object) {
        return new RestResponse(AJAX_SUCCESS, msg, object);
    }

    public static RestResponse failure(Object object) {
        return new RestResponse(AJAX_ERROR, FAILURE_MSG, object);
    }

    public static RestResponse failure(String msg, Object object) {
        return new RestResponse(AJAX_ERROR, msg, object);
    }

    public static RestResponse noAuth(Object object) {
        return new RestResponse(NO_AUTH, NO_AUTH_MSG, object);
    }

    public static RestResponse noAuth(String msg, Object object) {
        return new RestResponse(NO_AUTH, msg, object);
    }

    public static RestResponse timeout(Object object) {
        return new RestResponse(SERVER_TIMEOUT, TIMEOUT_MSG, object);
    }

    public static RestResponse timeout(String msg, Object object) {
        return new RestResponse(SERVER_TIMEOUT, msg, object);
    }

    public static RestResponse serverErr(Object object) {
        return new RestResponse(SERVER_ERROR_CODE, SERVER_ERROR_MSG, object);
    }

    public static RestResponse serverErr(String msg, Object object) {
        return new RestResponse(SERVER_ERROR_CODE, msg, object);
    }

	public Integer getRet() {
		return ret;
	}

	public void setRet(Integer ret) {
		this.ret = ret;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
    
    
}
